1. Field of the Invention
The present general inventive concept relates to a data processing apparatus and a data processing method, and more particularly, to a data processing apparatus and a data processing method which processes data files written in various byte orders.
2. Description of the Related Art
A data processing apparatus (hereinafter, to be called “system”) which has a general purpose computer system such as a PC and an embedded system such as a printer, includes a computer memory to store data therein, and a computer processor to read the data stored in the computer memory, process the read data or write the processed data to the computer memory.
Typically, the computer processor writes the data in the computer memory in byte unit (e.g. 2 bytes in a case of 16 bits). The order (hereinafter, to be called “byte order”) of writing the bytes of the data at an address of the computer memory is predetermined. The byte order may be classified into big-endian and little-endian. In the big-endian byte order, the computer processor encodes and stores data in the computer memory from its most significant bit. In the little-endian byte order, the computer processor encodes and stores data in the computer memory from its least significant bit.
Such byte order is the property of the computer processor, and may not be mattered if programmed in a single system. The byte order is, however, an important subject in network programming of two computer systems communicating with different byte orders with each other.
To solve the foregoing problem, the conventional invention designates the byte order to be used as the format of the data file, or notifies the byte order used to write the data in a header of the data file.
More specifically, if the particular byte order is designated in writing the data file (hereinafter, writing data file will be called “encoding”), the computer system checks the preset byte order of the data file as shown in FIG. 1 (S11). If the preset byte order is little-endian (S12), the computer system encodes the data file with a little-endian form (S13). If the preset byte order is not little-endian at operation S12, the computer system encodes the data file with a big-endian form (S14).
Meanwhile, if the byte order is written in the header of the data file, the computer system checks the byte order of its own as shown in FIG. 2 (S21). If the byte order of the computer system is little-endian (S22), the computer system writes 11 in the first two bytes in the header of the data file (S23). If the byte order of the computer system is not little-endian at operation S12, the computer system writes MM in the first two bytes in the header of the data file (S24).
To read the data file (hereinafter, to be called “decoding”) as encoded above two cases, the computer system checks the byte order of the data file in both the big-endian and little-endian forms, as shown in FIG. 3 (S31). At operation S31, if the particular byte order is designated by the file format, the computer system checks the designated byte order. If the byte order is written in the header of the data file, the computer system decodes the first two bytes of the header at a time and determines whether it is II or MM.
If it is determined at operation S31 that the byte order of the data file is little-endian (S32), the computer system checks the byte order of its own (S34). If it is determined at operation S34 that the byte order of the computer system is little-endian (S36), the computer system decodes the data file without converting the byte order of the data file (S39). If it is determined at operation S34 that the byte order of the computer system is not little-endian (S36), the computer system converts the byte order of the data file into big-endian and decodes the data file (S38).
If it is determined at operation S31 that the byte order of the data file is not little-endian (S32), the computer system checks whether the byte order of the data file is big-endian (S33). If the byte order of the data file is not big-endian, the computer system detects and processes as an error (S40).
If it is determined at operation S31 that the byte order of the data file is big-endian (S33), the computer system checks the byte order of its own (S35). If determined at operation S35 that the byte order of the computer system is little-endian (S36), the computer system converts the byte order of the data file into little-endian and decodes the data file (S38). If the byte order of the computer system is not little-endian, the computer system decodes the data file without converting the byte order of the data file (S39).
As described above, the conventional invention checks the byte order of the data file or the system byte order to encode the data file with the system. Also, the conventional invention checks the byte order of both the data file and the system to decode the data file.
As the conventional invention always checks the byte order of the data file and/or the computer system, the data is not processed efficiently.
Also, as the conventional invention checks the byte order of the computer system, a program should be developed corresponding to respective computer systems, which is very inefficient.